<template>
	<view class="shopDetails">
			<tui-navigation-bar maxOpacity="0" :titleSize="18" :titleLineHeight="18" :titlefontWeight="800"   @init="initNavigation" title="个人信息" backgroundColor="#fff" color="#000">
			 <view class="tui-header-icon" :style="{ marginTop: top + 'px' }">
			   <tui-icon name="arrowleft" color="#333" @click="back"></tui-icon>
			 </view>
			</tui-navigation-bar>
		 
		<view class="shopDetails_content" :style="{ marginTop: marginTp + 'px' }">
			  <tutor-videoImg-swiper :ossUrl="ossUrl" :imgUrls="imgUrls"></tutor-videoImg-swiper>
			<view class="titleText">
				<view class="titleL">
					<view class="titleL_text"><text>{{tutorDetails.assistantName}}</text></view>
					<tui-form-button @click="goUserInfoEdit" margin="0 0 0 20rpx" width="120rpx" size="24" height="42rpx" plain background="#63d6d3" color="#63d6d3" radius="100rpx">
						<image class="icon" src="/static/tutor/order/icon_edit@2x.png"></image>编辑
					</tui-form-button> 
				</view>
				<view class="titleR">
					<text>{{tutorDetails.rates}}</text>
					<text class="priceTime">元/小时</text>
				</view>
			</view>
			<view class="tags">
				<view class="tag"><text>{{tutorDetails.personalSignature}}</text></view> 
			</view>
			<view class="timeText">
				<text>营业时间：{{tutorDetails.begintime}}—{{tutorDetails.endtime}}</text>
			</view>
			<view class="addressText">
				  教练地址：<text class="ct">{{tutorDetails.poi&&tutorDetails.poi.district}}</text>
			</view>
			<view class="tabList">
				<view class="tabList_tab">
					<tutor-tab :list="['最新动态','评价列表']" @clickSwtichTab="clickSwtichTab" :atciveIndex="atciveIndex"></tutor-tab>
				</view>
					<view class="contentDynamic">
						<z-paging ref="paging" :fixed="false" v-model="listData" @query="queryList">
						<view class="shopImg" v-if="!atciveIndex">
							<!-- <text class="newest">最新动态</text>
							<view style="margin-top: 24rpx;margin-bottom: 40rpx;">
								 <tutor-dynamicItem :dynamicList="upDymicList" :ossUrl="ossUrl"></tutor-dynamicItem>
							</view>
							<text class="newest" >动态列表</text> -->
							<view>
								 <tutor-dynamicItem :dynamicList="listData" :ossUrl="ossUrl"></tutor-dynamicItem>
							</view>
						</view>
						<view class="appraiseItems" v-else>
								<tutor-appraiseItem :ossUrl="ossUrl" :listData="listData"></tutor-appraiseItem>
						</view>
					</z-paging> 
				</view> 
				 
			</view>
		</view> 
	</view>
</template>

<script> 
	import { getTutorDetails,getTutorTime } from "@/http/api/tutor/tutor.js"  
	import { getAppraiseList } from "@/http/api/appraise/appraise.js"  
	import { myDynamicList,myLoginDynamicList } from "@/http/api/dynamic/dynamic.js"

	export default { 
		data() {
			return {
				top: 0, //标题图标距离顶部距离
				marginTp:0,
				isAgreement:false,
				listData:[],//评价数据
				upDymicList:[],//最新动态
				ossUrl:getApp().globalData.ossurl,//图片前缀
				tutorDetails:{},//教练信息
				dymicList:[],//动态列表
				imgList: ['https://img1.baidu.com/it/u=802052110,461511387&fm=253&fmt=auto&app=138&f=JPEG?w=400&h=214','https://img1.baidu.com/it/u=802052110,461511387&fm=253&fmt=auto&app=138&f=JPEG?w=400&h=214'],
				atciveIndex:0,//切换商家图片和教练列表
				auditStatus: false
			}
		}, 
		onUnload(){
			uni.$off('tutorRefresh')
		},
		onLoad(){
			this.getDetails() 
				uni.$on('tutorRefresh',(e)=>{
				 if(e){
					 this.getDetails()
				 }
			 })
		},
		computed:{
			assistantId(){
				return this.$store.state.userTutorDetails.id
			},
			imgUrls(){
					return  this.tutorDetails.detailImgs 
				}, 
			// videoline(){
			// 	if(this.tutorDetails.detailImgs&&this.tutorDetails.detailImgs.length || false){  
			// 		if(this.isImage(this.tutorDetails.detailImgs[this.tutorDetails.detailImgs.length - 1])){
			// 				return ''
			// 		}else{
			// 				return  this.tutorDetails.detailImgs[this.tutorDetails.detailImgs.length - 1]
			// 		} 
			// 	}
			// }
			
		},  
		methods: {
			isImage(filename) {
			    const imageExtensions = ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.svg'];
			    const fileExtension = filename.slice(filename.lastIndexOf('.'));
			    return imageExtensions.includes(fileExtension.toLowerCase());
			},
			initNavigation(e) { 
			 		this.top = e.top;
					this.marginTp =   e.height
			},
			back() {
					uni.navigateBack({
							        delta: 1
							    });;
				},
			examine(arr, index) {
				uni.previewImage({
					urls: arr,
					current: index
				});
			},
			clickSwtichTab(data){
				this.atciveIndex= data.index
				this.$refs.paging.reload()
			},
			//进入编辑页面
			goUserInfoEdit(){
				let data=JSON.stringify(this.tutorDetails)
			   uni.navigateTo({
			   	url:'/pages/personalDetails/modules/userInfoEdit/userInfoEdit?tutorDetails='+data
			   })	
			},
			//获取教练详情
			getDetails(){
				getTutorDetails({id:this.assistantId}).then(res=>{
					if(res.code===200){
					   this.tutorDetails=res.data
					}
					console.log(res,'获取当前教练信息')
				})
			},
			//加载动态和评价列表
			queryList(pageNo, pageSize) { 
				if(!this.atciveIndex){
					//获取最新动态
					// myLoginDynamicList({pageNum:pageNo,pageSize,queryType:2}).then(res => {
					// 	if (res.code == 200) {
					// 		  this.upDymicList=res.rows&&res.rows.slice(0,1) || [] 
					// 	} else {
					// 		this.$utils.toast(res.msg);
					// 	}
					// }) 
					myLoginDynamicList({pageNum:pageNo,pageSize}).then(res => {
						if (res.code == 200) {
							  this.$refs.paging.complete(res.rows); 
						} else {
							this.$utils.toast(res.msg);
						}
					})
				}else{
					//获取教练评论
					 getAppraiseList({pageNum:pageNo,pageSize,commentType:2,beUserType:2,beUserId:this.tutorDetails.id}).then(res => {
						if (res.code == 200) { 
							 this.$refs.paging.complete(res.rows); 
						} else {
							this.$utils.toast(res.msg);
						}
					 }) 
				 }
			}
		}
	}
</script>

<style lang="scss" scoped>
@import './personalDetails.scss';
</style>